package leetcode.editor.cn;
//[50]Pow(x, n)
public class PowxN50{
public static void main(String[] args) {
   Solution solution = new PowxN50().new Solution();
   
}

  //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public double myPow(double x, int n) {
//        if (n==0)return 1.0;
//
//        if (n<0){
//            return 1.0/myPow(x,-n);
//        }
//        double res = myPow(x,n/2);
//        if (n%2==0){
//            return res * res;
//        }
//        return x * res * res;
        return mPow(x,n);
    }
    //int n ----> long n .. Integer.min-->MAX 越界！！！
    public double mPow(double x,long n){
        if (n==0)return 1.0;
        if (n<0){
            return 1.0/mPow(x,-n);
        }
        double res = mPow(x,n/2);
        if (n%2==0){
            return res * res;
        }
        return x * res * res;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}